using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;


namespace k_mean_clustering
{
    class Test_clustering_multithread
    {
        string m_Test_1_obvious_group;
        string m_Test_10_obvious_groups;
        string m_Test_2_disctinct_groups;

        public Test_clustering_multithread()
        {
            m_Test_1_obvious_group =
                "TEST Clustering_multithread -- 1 Obvious Group: Test Failed.";
            m_Test_10_obvious_groups =
                "TEST Clustering_multithread -- 10 Obvious Groups: Test Failed.";
            m_Test_2_disctinct_groups=
                "TEST Clustering_multithread -- 2 disctinct Groups: Test Failed.";

            this.Test_1_obvious_groups();
            this.Test_10_obvious_groups();
            this.Test_2_disctinct_groups();

            Console.WriteLine(m_Test_1_obvious_group);
            Console.WriteLine(m_Test_10_obvious_groups);
            Console.WriteLine(m_Test_2_disctinct_groups);
        }
        
        //On vérifie que l'algo est capable de reconnaitre qu'il n'y a qu'un groupe lorsque touts les individus sont identiques
        public void Test_1_obvious_groups()
        {
            double[,] trivial_container= new double[10,2];
            Data trivial_data= new Data(10,2);
            
            for (int i=0;i<10;i++)
            {   
                trivial_container[i,0]=0;
                trivial_container[i,1]=0;
               
            }
            trivial_data.container = trivial_container;
            Clustering_multithread clusterTest1= new Clustering_multithread(trivial_data,2);
            
            if (clusterTest1.NumberNonEmptyGroups == 1)
            {
                m_Test_1_obvious_group = "TEST Clustering_multithread -- 1 Obvious Group: Test Succeeded."; 
            }
        }

        //On vérifie que l'algo est capable de trouver dix groupes quand il y a 10 individus distincts.
        public void Test_10_obvious_groups()
        {
            double[,] trivial_container2 = new double[10, 2];
            Data trivial_data2 = new Data(10, 2);

            for (int i = 0; i < 10; i++)
            {
                trivial_container2[i, 0] = i;
                trivial_container2[i, 1] = i;

            }
            trivial_data2.container = trivial_container2;
            Clustering_multithread clusterTest2 = new Clustering_multithread(trivial_data2, 10);
            if (clusterTest2.NumberNonEmptyGroups == 10)
            {
                m_Test_10_obvious_groups = "TEST Clustering_multithread -- 10 Obvious Groups: Test Succeeded.";
            }
        }
        //On vérifie que l'algoi est capable de trouver 2 groupes quand 
        //il y a effectivement deux groupe distincts. 

        public void Test_2_disctinct_groups()
        {
            double[,] container = new double[100, 2];
            Data data = new Data(100, 2);

            for (int i = 0; i < 50; i++)
            {
                container[i, 0] = 0;
                container[i, 1] = 0;

                container[i+50, 0] = 1;
                container[i+50, 1] = 1;
            }

            data.container=container;
            int[] centroids = new int[2];
            centroids[0] = 0;
            centroids[1] = 99;
            Clustering_multithread clusterTest3 = new Clustering_multithread(data, 2,centroids);
            int count = 0;
            for (int i = 1; i < 50; i++)
            {
                if(clusterTest3.Groups[i]==clusterTest3.Groups[i-1] && clusterTest3.Groups[i+50]==clusterTest3.Groups[i-1+50])
                { count = count + 1; }

            }
            if (count==49)
            {
                m_Test_2_disctinct_groups = "TEST Clustering_multithread -- 2 disctincts groups: Test Succeeded.";
            }
        }
    }
}
